package com.juc;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicIntegerArray;

public class AtomicJuc {
    public static AtomicIntegerArray array = new AtomicIntegerArray(10);
//    public static Atomic*Reference
//    public static Atomic*FileUpdate
    public static AtomicInteger stock = new AtomicInteger(10000);

    static class StockRunnable implements Runnable {
        @Override
        public void run() {
            if(stock.get() > 0) {
                stock.decrementAndGet();
            }
        }
    }
    public static void main(String[] args) {

        ExecutorService pool = Executors.newCachedThreadPool();

        StockRunnable task = new StockRunnable();

        for (int i = 0; i < 10000; i++) {
            pool.execute(task);
        }

        System.out.println(stock.get());
        pool.shutdown();

    }
}
